/*****************************************************************************************
   
   Copyright (c) Microsoft Corporation. All rights reserved.

   Use of this code sample is subject to the terms of the Microsoft
   Permissive License, a copy of which should always be distributed with
   this file.  You can also access a copy of this license agreement at:
   http://www.microsoft.com/resources/sharedsource/licensingbasics/permissivelicense.mspx

 ****************************************************************************************/

using System;

namespace GrooveWebServicesV12Helpers
{
	public class MessageAttachment
	{
		private GrooveWebServicesV12Helpers.MessageContent m_MessageContent;
		
		private GrooveMessagesWebService.MessageAttachment m_MessageAttachment;

		public enum AttachmentType
		{
			File = 0x0,
			Voice = 0x1,
			Unknown = 0xFF
		}

		public MessageAttachment(GrooveWebServicesV12Helpers.MessageContent i_MessageContent, GrooveMessagesWebService.MessageAttachment i_MessageAttachment)
		{
			m_MessageContent = i_MessageContent;
			m_MessageAttachment = i_MessageAttachment;
		}

		public MessageAttachment(string i_DisplayName, GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType i_AttachmentType, string i_FileURI)
		{
			m_MessageAttachment = new GrooveWebServicesV12Helpers.GrooveMessagesWebService.MessageAttachment();

			//  Validate parameters
			if (!System.IO.File.Exists(i_FileURI))
				throw new System.ArgumentException("Invalid FileURI!");

			//  Populate message attachment
			m_MessageAttachment.DisplayName = i_DisplayName;
			m_MessageAttachment.AttachmentFileURI = i_FileURI;

			switch (i_AttachmentType)
			{
				case GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.File:
				{
					m_MessageAttachment.Type = GrooveMessagesWebService.AttachmentType.File;
					break;
				}

				case GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.Voice:
				{
					m_MessageAttachment.Type = GrooveMessagesWebService.AttachmentType.Voice;
					break;
				}

				default:
				{
					m_MessageAttachment.Type = GrooveMessagesWebService.AttachmentType.Unknown;
					break;
				}
			}
		}

		public MessageAttachment(string i_DisplayName, GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType i_AttachmentType, byte[] i_Content)
		{
			m_MessageAttachment = new GrooveWebServicesV12Helpers.GrooveMessagesWebService.MessageAttachment();

			//  Populate message attachment
			m_MessageAttachment.DisplayName = i_DisplayName;
			m_MessageAttachment.Content = i_Content;

			switch (i_AttachmentType)
			{
				case GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.File:
				{
					m_MessageAttachment.Type = GrooveMessagesWebService.AttachmentType.File;
					break;
				}

				case GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.Voice:
				{
					m_MessageAttachment.Type = GrooveMessagesWebService.AttachmentType.Voice;
					break;
				}

				default:
				{
					m_MessageAttachment.Type = GrooveMessagesWebService.AttachmentType.Unknown;
					break;
				}
			}
		}

		#region MessageAttachment Properties And Methods

		internal GrooveMessagesWebService.MessageAttachment RawMessageAttachment
		{
			get
			{
				return m_MessageAttachment;
			}
		}

		public GrooveWebServicesV12Helpers.MessageContent MessageContent
		{
			get
			{
				return m_MessageContent;
			}
		}

		public string URI
		{
			get
			{
				return m_MessageAttachment.AttachmentFileURI;
			}
		}

		public byte[] Content
		{
			get
			{
				return m_MessageAttachment.Content;
			}
		}

		public string DisplayName
		{
			get
			{
				return m_MessageAttachment.DisplayName;
			}
		}

		public int Size
		{
			get
			{
				return m_MessageAttachment.Size;
			}
		}

		public GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType Type
		{
			get
			{
				switch (m_MessageAttachment.Type)
				{
					case GrooveMessagesWebService.AttachmentType.File:
					{
						return GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.File;
					}

					case GrooveMessagesWebService.AttachmentType.Voice:
					{
						return GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.Voice;
					}

					default:
					{
						return GrooveWebServicesV12Helpers.MessageAttachment.AttachmentType.Unknown;
					}
				}
			}
		}

		#endregion

	}
}
